home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / mlpmodul.sit / MacLogimoPlus Documentation / DEF4 Files / fxEventTasks.DEF < prev    next >
Encoding:
Modula Definition  |  1990-06-14  |  6.5 KB  |  143 lines  |  [TEXT/PMED]

  1. DEFINITION MODULE fxEventTasks; (* Franz Kronseder / ETHZ / 02.08.85 *)
  2.                                 (* last modified 09.08.85 *)
  3.  (* a simple scheduler intended to allow arranging  a Modula-2 *)
  4.  (* program on Macintosh  as a collection of Event handling    *)
  5.  (* subroutines *)
  6.  
  7.  (* this module is conceptually built on top of the Macintosh *)
  8.  (* Toolbox Event Manager and its main goal is to support the *)
  9.  (* decomposition of an otherwise tremenduously large CASE-statement *)
  10.  (* for event handling into independent modules *)
  11.  (* from Inside Macintosh: ABOUT THE TOOLBOX EVENT MANAGER: *)
  12.  (* "A typical Macintosh application program is event-driven: It decides *)
  13.  (* what to do from moment to moment by asking the Event Manager for *)
  14.  (* events and responding to them one by one in whatever way is *)
  15.  (* appropriate."  *)
  16.  
  17. IMPORT MacBase,EventMgr;
  18. EXPORT QUALIFIED
  19.  everyEvent,nullEvent,mouseDown,mouseUp,keyDown,keyUp,autoKey,updateEvt,
  20.  diskEvt,activateEvt,abortEvt,reserveEvt,driverEvt,
  21.  app1Evt,app2Evt,app3Evt,app4Evt,
  22.  optionKey,alphaLock,ShiftKey,CmdKey,BtnState,activeFlag,changeFlag,
  23.  
  24.  NoErr,OsErr,EventRecord,EventHandler,TaskProc,
  25.  TaskPtr,TaskDefRec,defaultTask,
  26.  pushTask,popTask,popallTasks,
  27.  AbortCode,NoAbort,abortEvtFound,
  28.  PollEventTasks,GetBusyReadEvent,ErrorText;
  29.         
  30. (*------ from EventMgr.def----------------
  31.   EventRecord = RECORD
  32.                   what:      INTEGER;
  33.                   CASE BOOLEAN  OF
  34.                     TRUE : message: LongInt;
  35.                   | FALSE: msgchar: ARRAY [0..3] OF CHAR;
  36.                   END;
  37.                   when:      LongInt;
  38.                   where:     Point;
  39.                   CASE BOOLEAN OF
  40.                     TRUE : modifiers: BITSET;
  41.                   | FALSE: modifwrd : CARDINAL; (* modifier word *)
  42.                   END;
  43.                 END;  (* record *)
  44. ------ from EventMgr.def----------------*)
  45.  
  46. CONST NoErr = 0; (* ok value for OsErr *)
  47.       NoAbort = 0; (* for AbortCode *)
  48.  
  49. CONST
  50.   everyEvent  = EventMgr.everyEvent  ;
  51.   nullEvent   = EventMgr.nullEvent   ; mouseDown  = EventMgr.mouseDown;
  52.   mouseUp     = EventMgr.mouseUp     ; keyDown    = EventMgr.keyDown;
  53.   keyUp       = EventMgr.keyUp       ; autoKey    = EventMgr.autoKey;
  54.   updateEvt   = EventMgr.updateEvt   ; diskEvt    = EventMgr.diskEvt;
  55.   activateEvt = EventMgr.activateEvt ; abortEvt   = EventMgr.abortEvt;
  56.   reserveEvt  = EventMgr.reserveEvt  ; driverEvt  = EventMgr.driverEvt;
  57.   app1Evt     = EventMgr.app1Evt     ; app2Evt    = EventMgr.app2Evt;
  58.   app3Evt     = EventMgr.app3Evt     ; app4Evt    = EventMgr.app4Evt;
  59.  
  60.   (* modifiers !!! here Bitnumbers in BITSET !!! *)
  61.   optionKey = EventMgr.optionKey; (*2048, Bit 3 of high byte  *)
  62.   alphaLock = EventMgr.alphaLock; (*1024, Bit 2  *)
  63.   ShiftKey  = EventMgr.ShiftKey;  (* 512, Bit 1  *)
  64.   CmdKey    = EventMgr.CmdKey;    (* 256, Bit 0  *)
  65.   BtnState  = EventMgr.BtnState;  (* 128, Bit 7 of low byte is mouse button state  *)
  66.   activeFlag= EventMgr.activeFlag;(*   1, bit 0 of modifiers for activate event  *)
  67.   changeFlag= EventMgr.changeFlag;(*   2, bit 1 of modifiers for activate event  *)
  68.  
  69.  
  70. TYPE OsErr = MacBase.OsErr; LongInt = MacBase.LongInt;
  71.      EventRecord = EventMgr.EventRecord;
  72.      EventHandler = PROCEDURE (VAR EventRecord):BOOLEAN;
  73.                     (* this procedure type is used by the scheduler for *)
  74.                     (* distributing events obtained by GetNextEvent *)
  75.                     (* to the activated tasks *)
  76.                     (* the EventHandler first has to analyse the event, *)
  77.                     (* then either handle it and return TRUE or not *)
  78.                     (* handle it and return FALSE  *)
  79.                     (* EventHandler(NIL) is a legal value *)
  80.  
  81.      TaskProc = PROCEDURE ():OsErr;
  82.                 (* this procedure type is used for specifying the *)
  83.                 (* initialization, termination and periodic activities *)
  84.                 (* attributed to a task *)
  85.                 (* TaskProc(NIL) is a legal value *)
  86.  
  87.      TaskPtr = POINTER TO TaskDefRec;
  88.      TaskDefRec = RECORD (* Task Definition Record *)
  89.                   SetupProc  : TaskProc;    (* alloc and init task data *)
  90.                   EventProc  : EventHandler;(* check and treat Events *)
  91.                   CleanupProc: TaskProc;    (* cleanup and dealloc task data *)
  92.                   IdleProc:    TaskProc;    (* periodic action between Events *)
  93.  
  94.                   TaskError  : OsErr;       (* some associated data *)
  95.                   TaskEnabled: BOOLEAN;     (* EventHandler on/off switch*)
  96.                   RefCon     : LongInt;     (* 32 bits of User Data *)
  97.                  END; (*record*)
  98.       (* The variables of type TaskDefRec must be supplied by the      *)
  99.       (* task defining modules and contain valid data during the whole *)
  100.       (* lifetime of the task, not just during initialisation          *)
  101.       (* fxEventTasks maintains only an array of TaskPtrs to such *)
  102.       (* TaskDefRecs *)
  103. (*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*)
  104. VAR AbortCode : INTEGER;  (* for signalling occurence of abort events *)
  105.  
  106. PROCEDURE abortEvtFound():BOOLEAN;
  107.  (* returns true, iff AbortCode <> 0 *)
  108.  
  109. PROCEDURE pushTask(Task:TaskPtr):OsErr;
  110.  (* push Task onto the scheduler and activate it *)
  111.  (* by executing its SetupProc *)
  112.  
  113. PROCEDURE popTask(VAR Task:TaskPtr):OsErr;
  114.  (* pop a Task from the scheduler and deactivate it by *)
  115.  (* executing its CleanupProc *)
  116.  
  117. PROCEDURE popallTasks():OsErr;
  118.  (* deactivate and remove all entries in the Task scheduler *)
  119.  
  120. PROCEDURE PollEventTasks;
  121.  (* to be called repeatedly in the Main Loop of a Program    *)
  122.  (* PollEventTasks performs an EventMgr.GetNextEvent;        *)
  123.  (* distrubutes Events to the activated EventHandler;        *)
  124.  (* runs through activated IdleProcs if no Events available. *)
  125.  (* keyDown or AutoKey events that remain unhandled by the tasks *)
  126.  (* are buffered for GetBusyReadEvent which is for use by MODULE *)
  127.  (* Terminal. unhandled abortEvt are flagged in the AbortCode *)
  128.  (* variable *)
  129.  
  130. PROCEDURE defaultTask(VAR Task:TaskPtr);
  131.  (* IF Task=NIL then return pointer to internal default task *)
  132.  (* otherwise copy values of internal default task to Task^  *)
  133.  
  134. PROCEDURE GetBusyReadEvent(VAR event:EventRecord):BOOLEAN;
  135.  (* get keyDown and autoKey events that no active Task wanted to handle. *)
  136.  (* this enables the Module Terminal to run as lowest priority handler   *)
  137.  
  138. PROCEDURE ErrorText(error:OsErr; VAR text:ARRAY OF CHAR);
  139.  (* return error message for a given errorcode *)
  140.  (* not yet implemented, returns empty modula strings sofar *)
  141.  
  142. END fxEventTasks.
  143.